home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
DEMOS
/
SWARS
/
!Swars
/
Sources
/
c
/
!RunImage
next >
Wrap
Text File
|
1996-03-17
|
5KB
|
206 lines
/*******************************************************/
/* -=[FlY'96]=- StarWars scroller (no vertical deform) */
/*******************************************************/
/* includes */
#include <stdio.h>
#include <stdlib.h>
#include <kernel.h>
#include <swis.h>
#include <math.h>
#include "Swarshead.h"
#ifdef C4
#include "bbc.h"
#endif
#define C5
/* Global variables */
screen scr;
/* MAIN --------------------------------------- */
int main (void)
{
/* variables used */
FILE *in;
int i;
_kernel_swi_regs reg;
_kernel_oserror *err;
int block[8];
char char_buffer[8];
unsigned char *buf;
unsigned char *imgd;
unsigned int s[SCRLENGTH];
scrobj p[SCRLENGTH];
scr.mode = GFXMODE;
#ifdef C4
bbc_mode(scr.mode);
#endif
#ifdef C5
char_buffer[0] = 22;
char_buffer[1] = scr.mode;
reg.r[0] = (int)char_buffer;
reg.r[1] = 2;
if((err=_kernel_swi(OS_WriteN, ®, ®)) != NULL) {
fprintf(stderr,"OS_WriteN error : %s\n", err->errmess);
exit(EXIT_FAILURE);
}
#endif
/* OFF */
if((err=_kernel_swi(OS_RemoveCursors, ®, ®)) != NULL) {
fprintf(stderr,"OS_RemoveCursors error : %s\n", err->errmess);
exit(EXIT_FAILURE);
}
block[0] = 148;
block[1] = 149;
block[2] = 150;
block[3] = -1;
reg.r[0] = (int)block;
reg.r[1] = (int)block;
if((err=_kernel_swi(OS_ReadVduVariables, ®, ®)) != NULL) {
fprintf(stderr,"OS_ReadVduVariables error : %s\n", err->errmess);
exit(EXIT_FAILURE);
}
scr.ScreenStart = (unsigned char *)block[0];
scr.DisplayStart = (unsigned char *)block[1];
scr.TotalScreenSize = (unsigned int)block[2];
if((buf = calloc(SCRSIZE,sizeof(char))) == NULL) {
fprintf(stderr,"Cannot allocate %u bytes for buffer\n", SCRSIZE*sizeof(char));
exit(EXIT_FAILURE);
}
if((imgd = calloc(SCRSIZE,sizeof(char))) == NULL) {
fprintf(stderr,"Cannot allocate %u bytes for imgd\n", SCRSIZE*sizeof(char));
exit(EXIT_FAILURE);
}
/* load image */
#ifdef DEBUG
printf("Loading image\n");
#endif
if((in=fopen("<Swars$Dir>.Swarspic","rb")) == NULL) {
fprintf(stderr,"Cannot open \"swarspic\" for input\n");
exit(EXIT_FAILURE);
}
for (i=0;i<56;i++) buf[i] = fgetc(in); /* skip info bytes */
for(i=0; i<SCRSIZE; i++) buf[i] = fgetc(in);
fclose(in);
/* end load image into buffer */
/*-----------------------------------------------------------------------*/
/* init for the loop */
#ifdef DEBUG
printf("Building an object ...\n");
#endif
initobjet(p);
#ifdef DEBUG
printf("Initialising the steps ...\n");
#endif
initstep(s,p);
#ifdef DEBUG
for(i=SCRLENGTH;i>=LENGTHMAX;i--) printf("%u %u %u\n",p[i].start,p[i].stop,s[i]);
printf("And now the deformation effect ...\n");
#endif
do
{ /* wait vbl */
reg.r[0] = 19;
reg.r[1] = 0;
if((err=_kernel_swi(OS_Byte, ®, ®)) != NULL) {
fprintf(stderr,"OS_Byte error : %s\n", err->errmess);
exit(EXIT_FAILURE);
}
/* end wait vbl */
stretch(buf,imgd,s,p); /* stretch buffer onto the object and display */
scrolls(buf); /* scroll the original image one line up */
_kernel_swi(OS_Mouse, ®,®);
} while(reg.r[2] == 0);
return(0);
}
/*-----------------------------------------------------------------------*/
/*******************************/
/* Functions used in this code */
/*******************************/
void initobjet(scrobj *p)
{
int i;
for (i=SCRLENGTH-1;i>=LENGTHMAX;i--)
{
p[i].start=SCRLENGTH-i;
p[i].stop=SCRWIDTH-2*p[i].start-1;
}
}
/**************************************************************************/
void initstep(unsigned int *s, scrobj *p)
{
int i;
for (i=SCRLENGTH-1;i>=LENGTHMAX;i--)
{
s[i]=(SCRWIDTH << 8)/(p[i].stop);
}
}
/**************************************************************************/
void stretch(unsigned char *buf,unsigned char *imgd,unsigned int *s, scrobj *p)
{
unsigned char *ecran;
unsigned int i,j,k,z,stp,stl;
ecran=scr.DisplayStart;
for (i=SCRLENGTH-1;i>=LENGTHMAX;i--)
{
stp=s[i];
stl=0;
z=(p[i].start % SCRWIDTH) + i*SCRWIDTH;
k=p[i].stop;
for(j=0;j<k;j++)
{
ecran[z+j]=(imgd[z+j]=buf[i*SCRWIDTH+stl]);
stp=s[i]+stp;
stl=((1 << 8)+stp) >> 8;
}
}
}
/**************************************************************************/
void scrolls(unsigned char *buf)
{
unsigned char save[SCRWIDTH];
int i,j;
for (i=0;i<SCRWIDTH;i++)
{
save[i]=buf[i];
}
for (i=0;i<SCRLENGTH;i++)
{
for (j=0;j<SCRWIDTH;j++)
{
buf[i*SCRWIDTH+j]=buf[(i+1)*SCRWIDTH+j];
}
}
for (i=0;i<SCRWIDTH;i++)
{
buf[(SCRLENGTH-1)*SCRWIDTH+i]=save[i];
}
}